package com.czk.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.czk.mapper.TblNameMapper;
import com.czk.utils.DataSourceContext;
import com.czk.pojo.TblName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/6/23 16:32
 */
@RestController
@RequestMapping("/tbl")
public class TblNameController {
    @Autowired
    private TblNameMapper tblNameMapper;

    @GetMapping("/all")
    // @UseDataSource("ds1")
    public TblName toTblName() {
        // 设置数据源
        DataSourceContext.setDatasource("ds1");
        QueryWrapper<TblName> wrapper = new QueryWrapper<>();
        wrapper.eq("id", 2);
        TblName tblName = tblNameMapper.selectOne(wrapper);
        DataSourceContext.remove();
        return tblName;
    }
}
